$(document).ready(function () {
	//监测浏览窗口动态变化
	$(window).resize(function () {
		amend_modal_place( $('#edit_parameter_modal'));//修正弹窗位置  始终处于屏幕中央  预警设置
		//amend_modal_place( $('#edit_complain_status'));//修正弹窗位置  始终处于屏幕中央  投诉类型管理
	});

	//页面  table 超出滑动
	page_overflow_scroll();
	function page_overflow_scroll() {
		var define_table_dealing = $('.define-table-dealing');
		var define_table_dealend = $('.define-table-dealend');
		var define_content_dealing = $('#define_content_dealing');
	    var define_content_dealend = $('#define_content_dealend');
		var thead_height = define_content_dealing.find('thead').height();
		var tr_height = define_content_dealing.find('tbody').find('tr').height() * 7;
		define_table_dealing.css( 'height' , thead_height + tr_height );
		define_table_dealend.css( 'height' , thead_height + tr_height );
	}

	//监测用户当前选择显示项  处理中/处理完毕
	listen_user_select_show();
	function listen_user_select_show() {
		var dealing = $('#define-dealing');
		var dealend = $('#define-dealend');
		var deal_active = localStorage.getItem('deal_active');
		if( deal_active ){
			dealing.removeClass('define-active');
			$('.define-table-dealing').addClass('define-active');
			dealend.addClass('define-active');
			$('.define-table-dealend').removeClass('define-active');
		}else {
			dealend.removeClass('define-active');
			$('.define-table-dealend').addClass('define-active');
			dealing.addClass('define-active');
			$('.define-table-dealing').removeClass('define-active');
		}
	}

	//设置当前页面选中样式
	setting_style_the_page();
	function setting_style_the_page() {
		var first_menu_item = $('#sidebar-nav').find('a[href="#accounts-menu-first-03"]');//获取一级菜单可点击的a标签 "预警处理"
		var img_nav = first_menu_item.find('.define-nav');//获取导航图片
		var img_left = first_menu_item.find('.define-left');//获取转向图片
		var first_ul = $('#accounts-menu-first-03');//获取一级下拉菜单
		var first_ul_li_one = first_ul.children('li').eq(0);//获取  "预警处理"

		first_menu_item.addClass('define-active');//一级菜单添加左边横线
		img_nav.attr('src','/statics/images/sever_center_select.png');//切换导航图片
		img_left.addClass('define-rotate-active');//添加动画类
		first_ul.addClass('in');//展拉一级菜单
		first_ul_li_one.addClass('define-active');//li添加左边横线

	}

	//分页切换效果
	page_style_switch();
	function page_style_switch() {
		var page_ = $('.define-paging');
		var the_first_page = $('#the_first_page');//获取首页
		var prev_page = $('#prev_page');//获取上一页
		var next_page = $('#next_page');//获取下一页
		var the_last_page = $('#the_last_page');//获取尾页

		// 123456
		page_.delegate('.define-page','click',function () {
			page_.find('.define-page').removeClass('define-active');
			$(this).addClass('define-active');
		});

		// 上一页
		prev_page.on('click',function () {
			var active_page = page_.find('.define-active');
			if(active_page.text() > 1){
				page_.find('.define-page').removeClass('define-active');
				active_page.prev().addClass('define-active')
			}
		});

		// 下一页
		next_page.on('click',function () {
			var active_page = page_.find('.define-active');
			if(active_page.text() < 5){
				page_.find('.define-page').removeClass('define-active');
				active_page.next().addClass('define-active')
			}
		});

		// 首页
		the_first_page.on('click',function () {
			page_.find('.define-page').removeClass('define-active');
			page_.find('.define-page').eq(0).addClass('define-active');
		});

		// 尾页
		the_last_page.on('click',function () {
			page_.find('.define-page').removeClass('define-active');
			page_.find('.define-page').eq(4).addClass('define-active');
		});

	}

	//切换  处理中\处理完毕
	switch_deal_status();
	function switch_deal_status() {
		var dealing = $('#define-dealing');
		var dealend = $('#define-dealend');
		dealing.on('click',function () {
			dealend.removeClass('define-active');
			$('.define-table-dealend').addClass('define-active');
			dealing.addClass('define-active');
			$('.define-table-dealing').removeClass('define-active');
			localStorage.removeItem('deal_active');
		});
		dealend.on('click',function () {
			dealing.removeClass('define-active');
			$('.define-table-dealing').addClass('define-active');
			dealend.addClass('define-active');
			$('.define-table-dealend').removeClass('define-active');
			localStorage.setItem('deal_active','ture');
		});
	}

	//弹层  修正弹窗位置  始终处于屏幕中央
	function amend_modal_place($modal) {
		var window_width = $(window).width();
		var window_height = $(window).height();
		var width = $modal.width();
		var height = $modal.height();

		var left = ( window_width - width ) / 2;
		var top  = ( window_height - height ) / 2;

		$modal.css('left',left);
		$modal.css('top',top);
	}

	//弹层  点击详情  展示弹窗  处理中
	show_modal_click_detail();
	function show_modal_click_detail() {
		var define_content_dealing = $('#define_content_dealing');
		define_content_dealing.delegate('.define_detail','click',function () {
			amend_modal_place( $('#edit_parameter_modal'));//修正弹窗位置  始终处于屏幕中央  预警设置
			$('#edit_parameter_modal').modal({keyboard:false});
		})
	}

	//弹层  点击详情  展示弹窗  处理完毕
	show_modal_click_detai_dealed();
	function show_modal_click_detai_dealed() {
		var define_content_dealend = $('#define_content_dealend');
		define_content_dealend.delegate('.define_detail','click',function () {
			amend_modal_place( $('#edit_parameter_modal'));//修正弹窗位置  始终处于屏幕中央  预警设置
			$('#edit_parameter_modal').modal({keyboard:false});
		})
	}

});